<?php

namespace App\Http\Controllers\Mobile\Personal;

use App\Models\Common\CollOption;
use App\Models\Personal\Resume;
use Illuminate\Http\Request;
use Style;

class PersonalCookieController extends CommonController{
    /**
     * 设置个人有没有登录12小时后没刷新的记录
     * @param Request $request
     */
    public function setPersonalCookie(){
        $user = auth()->guard('personal')->user();
        $resume = Resume::where('default', 1)->where('uid', $user->uid)->first(['updatetime', 'id', 'mobile', 'job_status']);
        if(!empty($resume)){
            $twelvehours = date('Y-m-d H:i:s', strtotime("-6 hours"));//12小时
            if($twelvehours > $resume->updatetime){
                $resume->job_status = CollOption::getOptionName($resume->job_status, 'job_status');
                return response()->json(['status' => 1, 'info' => $resume]);
            }else{
                return response()->json(['status' => 2]);
            }
        }
    }

    /**
     * 6小时后没刷新简历
     * @param Request $request
     */
    public function cookieResumeRefresh(Request $request){
        $user = auth()->guard('personal')->user();
        $input['updatetime'] = date('Y-m-d H:i:s', time());
        $input['xs_status']=0;
        $result = Resume::where('default', 1)->where('uid', $user->uid)->update($input);
        if(!empty($result)){
            return response()->json(['status' => 1, 'msg' => '刷新简历成功！']);
        }else{
            return response()->json(['status' => 2, 'msg' => '刷新简历失败，可能用户退出登录！']);
        }
    }
}